﻿namespace ACCOUNTING
{
    using ACCOUNTING.LVY.Business;
    using ACCOUNTING.My.Resources;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    [DesignerGenerated]
    public class ADVAccount : UserControl
    {
        private static List<WeakReference> __ENCList = new List<WeakReference>();
        [AccessedThroughProperty("CmdShow")]
        private Button _CmdShow;
        [AccessedThroughProperty("TxtCode")]
        private TextBox _TxtCode;
        [AccessedThroughProperty("TxtName")]
        private TextBox _TxtName;
        private IContainer components;
        private string mCode;
        private string mCondtions;
        private string mDefaultValue;
        private string mFieldNameFilter;
        private string mKeyFilter;
        private string mName;
        private bool mOnlyDigit;
        private bool mReadOnly;
        private bool mUpperText;
        private string mValue;
        private int mWithCode;

        public event GotfocusEventHandler Gotfocus;

        public event KeyPressEventHandler KeyPress;

        public event LostFocusEventHandler LostFocus;

        public event ValueChangedEventHandler ValueChanged;

        public ADVAccount()
        {
            base.Resize += new EventHandler(this.ADVList_Resize);
            List<WeakReference> list = __ENCList;
            lock (list)
            {
                __ENCList.Add(new WeakReference(this));
            }
            this.mValue = "";
            this.mCode = "";
            this.mName = "";
            this.mWithCode = 80;
            this.mOnlyDigit = false;
            this.mUpperText = true;
            this.mCondtions = "";
            this.mKeyFilter = "";
            this.mFieldNameFilter = "";
            this.mDefaultValue = "";
            this.mReadOnly = false;
            this.InitializeComponent();
        }

        private void ADVList_Resize(object sender, EventArgs e)
        {
            this.Height = this.TxtCode.Height;
            this.CmdShow.Left = (this.TxtName.Right - this.CmdShow.Width) - 2;
        }

        private void CmdShow_Click(object sender, EventArgs e)
        {
            string pValue = SearchModule.SearchTaiKhoan("", this.mKeyFilter, this.mFieldNameFilter, this.mCondtions, "");
            if (LVYModule.ReturnIfNull(pValue, "", modGeneral.TypeOfValue.Nothing).ToString().Trim() != "")
            {
                object instance = Strings.Split(pValue, "|", -1, CompareMethod.Binary);
                if (Information.UBound((Array) instance, 1) == 2)
                {
                    this.TxtCode.Text = NewLateBinding.LateIndexGet(instance, new object[] { 1 }, null).ToString().Trim();
                    this.TxtCode.Tag = NewLateBinding.LateIndexGet(instance, new object[] { 1 }, null).ToString().Trim();
                    this.TxtName.Text = NewLateBinding.LateIndexGet(instance, new object[] { 2 }, null).ToString().Trim();
                    this.Value = Conversions.ToString(NewLateBinding.LateIndexGet(instance, new object[] { 0 }, null));
                    ValueChangedEventHandler valueChangedEvent = this.ValueChanged;
                    if (valueChangedEvent != null)
                    {
                        valueChangedEvent(this, null);
                    }
                }
            }
            else
            {
                this.TxtCode.Text = Conversions.ToString(this.TxtCode.Tag);
            }
            this.ParentForm.SelectNextControl(this, true, true, true, true);
        }

        private void CmdShow_GotFocus(object sender, EventArgs e)
        {
            this.TxtCode.Focus();
        }

        private void CmdShow_MouseLeave(object sender, EventArgs e)
        {
            if (!this.mReadOnly)
            {
                this.CmdShow.BackgroundImage = ACCOUNTING.My.Resources.Resources.ButtonLight;
            }
        }

        private void CmdShow_MouseMove(object sender, MouseEventArgs e)
        {
            if (!this.mReadOnly)
            {
                this.CmdShow.BackgroundImage = ACCOUNTING.My.Resources.Resources.ButtonActive;
            }
        }

        public string CodeDisplay()
        {
            return this.TxtCode.Text.ToString().Trim();
        }

        [DebuggerNonUserCode]
        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void GetValue()
        {
            if (!this.mReadOnly)
            {
                ValueChangedEventHandler valueChangedEvent;
                if (this.TxtCode.Text.Trim() == "")
                {
                    this.TxtCode.Tag = "";
                    this.TxtName.Text = "";
                    if (this.mValue.Trim() != "")
                    {
                        this.mValue = "";
                        valueChangedEvent = this.ValueChanged;
                        if (valueChangedEvent != null)
                        {
                            valueChangedEvent(this, null);
                        }
                    }
                    this.ParentForm.SelectNextControl(this, true, true, true, true);
                }
                else if (LVYModule.ReturnIfNull(this.TxtCode.Text, "", modGeneral.TypeOfValue.Nothing).ToString().Trim() == LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(this.TxtCode.Tag), "", modGeneral.TypeOfValue.Nothing).ToString().Trim())
                {
                    this.ParentForm.SelectNextControl(this, true, true, true, true);
                }
                else if (this.TxtCode.Text.ToString().Trim() != LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(this.TxtCode.Tag), "", modGeneral.TypeOfValue.Nothing).ToString().Trim())
                {
                    string pValue = SearchModule.SearchTaiKhoan(this.TxtCode.Text, this.mKeyFilter, this.mFieldNameFilter, this.mCondtions, "");
                    if (LVYModule.ReturnIfNull(pValue, "", modGeneral.TypeOfValue.Nothing).ToString().Trim() != "")
                    {
                        object instance = Strings.Split(pValue, "|", -1, CompareMethod.Binary);
                        if (Information.UBound((Array) instance, 1) == 2)
                        {
                            this.TxtCode.Text = NewLateBinding.LateIndexGet(instance, new object[] { 1 }, null).ToString().Trim();
                            this.TxtCode.Tag = NewLateBinding.LateIndexGet(instance, new object[] { 1 }, null).ToString().Trim();
                            this.TxtName.Text = NewLateBinding.LateIndexGet(instance, new object[] { 2 }, null).ToString().Trim();
                            if (Operators.ConditionalCompareObjectNotEqual(NewLateBinding.LateIndexGet(instance, new object[] { 0 }, null), this.mValue, false))
                            {
                                this.Value = Conversions.ToString(NewLateBinding.LateIndexGet(instance, new object[] { 0 }, null));
                                valueChangedEvent = this.ValueChanged;
                                if (valueChangedEvent != null)
                                {
                                    valueChangedEvent(this, null);
                                }
                            }
                        }
                        this.ParentForm.SelectNextControl(this, true, true, true, true);
                    }
                    else
                    {
                        this.TxtCode.Text = LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(this.TxtCode.Tag), "", modGeneral.TypeOfValue.Nothing).ToString().Trim();
                    }
                }
            }
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
            this.TxtCode = new TextBox();
            this.TxtName = new TextBox();
            this.CmdShow = new Button();
            this.SuspendLayout();
            this.TxtCode.Dock = DockStyle.Left;
            Point point = new Point(0, 0);
            this.TxtCode.Location = point;
            this.TxtCode.Name = "TxtCode";
            Size size = new Size(80, 20);
            this.TxtCode.Size = size;
            this.TxtCode.TabIndex = 0;
            this.TxtName.Dock = DockStyle.Fill;
            point = new Point(80, 0);
            this.TxtName.Location = point;
            this.TxtName.Name = "TxtName";
            this.TxtName.ReadOnly = true;
            size = new Size(0xce, 20);
            this.TxtName.Size = size;
            this.TxtName.TabIndex = 2;
            this.CmdShow.BackgroundImage = ACCOUNTING.My.Resources.Resources.ButtonLight;
            this.CmdShow.FlatAppearance.BorderSize = 0;
            this.CmdShow.FlatStyle = FlatStyle.Flat;
            this.CmdShow.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Bold, GraphicsUnit.Point, 0xa3);
            point = new Point(0x10c, 2);
            this.CmdShow.Location = point;
            Padding padding = new Padding(0);
            this.CmdShow.Margin = padding;
            this.CmdShow.Name = "CmdShow";
            size = new Size(0x10, 0x10);
            this.CmdShow.Size = size;
            this.CmdShow.TabIndex = 3;
            this.CmdShow.UseVisualStyleBackColor = true;
            SizeF ef = new SizeF(6f, 13f);
            this.AutoScaleDimensions = ef;
            this.AutoScaleMode = AutoScaleMode.Font;
            this.Controls.Add(this.CmdShow);
            this.Controls.Add(this.TxtName);
            this.Controls.Add(this.TxtCode);
            padding = new Padding(0);
            this.Margin = padding;
            this.Name = "ADVAccount";
            size = new Size(0x11e, 20);
            this.Size = size;
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        public string NameDisplay()
        {
            return this.TxtName.Text.ToString().Trim();
        }

        public void SetDefault()
        {
            clsDMTaiKhoan khoan = new clsDMTaiKhoan();
            if (this.mDefaultValue.Trim() != "")
            {
                this.Value = khoan.GetTaiKhoan(this.mDefaultValue.Trim());
            }
        }

        private void TxtCode_GotFocus(object sender, EventArgs e)
        {
            if (this.mReadOnly)
            {
                this.ParentForm.SelectNextControl(this, true, true, true, true);
            }
        }

        private void TxtCode_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Return)
            {
                this.GetValue();
            }
            if (e.KeyCode == Keys.F4)
            {
                this.CmdShow_Click(RuntimeHelpers.GetObjectValue(sender), e);
            }
        }

        private void TxtCode_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (this.mUpperText)
            {
                e.KeyChar = Conversions.ToChar(e.KeyChar.ToString().ToUpper());
            }
        }

        private void TxtCode_Leave(object sender, EventArgs e)
        {
            if (LVYModule.ReturnIfNull(this.TxtCode.Text, "", modGeneral.TypeOfValue.Nothing).ToString().Trim() != LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(this.TxtCode.Tag), "", modGeneral.TypeOfValue.Nothing).ToString().Trim())
            {
                this.GetValue();
            }
            else if ((this.mValue.Trim() == "") & (this.TxtCode.Text.Trim() != ""))
            {
                this.GetValue();
            }
        }

        private void TxtName_GotFocus(object sender, EventArgs e)
        {
            this.ParentForm.SelectNextControl(this, true, true, true, true);
        }

        internal virtual Button CmdShow
        {
            [DebuggerNonUserCode]
            get
            {
                return this._CmdShow;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.CmdShow_Click);
                MouseEventHandler handler2 = new MouseEventHandler(this.CmdShow_MouseMove);
                EventHandler handler3 = new EventHandler(this.CmdShow_MouseLeave);
                EventHandler handler4 = new EventHandler(this.CmdShow_GotFocus);
                if (this._CmdShow != null)
                {
                    this._CmdShow.Click -= handler;
                    this._CmdShow.MouseMove -= handler2;
                    this._CmdShow.MouseLeave -= handler3;
                    this._CmdShow.GotFocus -= handler4;
                }
                this._CmdShow = value;
                if (this._CmdShow != null)
                {
                    this._CmdShow.Click += handler;
                    this._CmdShow.MouseMove += handler2;
                    this._CmdShow.MouseLeave += handler3;
                    this._CmdShow.GotFocus += handler4;
                }
            }
        }

        public string Conditions
        {
            get
            {
                return this.mCondtions;
            }
            set
            {
                this.mCondtions = value;
            }
        }

        public string DefaultValue
        {
            get
            {
                return this.mDefaultValue;
            }
            set
            {
                this.mDefaultValue = value;
            }
        }

        public string FieldNameFilter
        {
            get
            {
                return this.mFieldNameFilter;
            }
            set
            {
                this.mFieldNameFilter = value;
            }
        }

        public string KeyFilter
        {
            get
            {
                return this.mKeyFilter;
            }
            set
            {
                this.mKeyFilter = value;
            }
        }

        public bool OnlyDigit
        {
            get
            {
                return this.mOnlyDigit;
            }
            set
            {
                this.mOnlyDigit = value;
            }
        }

        public bool ReadOnly
        {
            get
            {
                return this.mReadOnly;
            }
            set
            {
                this.mReadOnly = value;
                this.TxtCode.ReadOnly = value;
                this.CmdShow.Enabled = !value;
                if (value)
                {
                    this.CmdShow.BackgroundImage = ACCOUNTING.My.Resources.Resources.ButtonBlur;
                }
                else
                {
                    this.CmdShow.BackgroundImage = ACCOUNTING.My.Resources.Resources.ButtonLight;
                }
            }
        }

        internal virtual TextBox TxtCode
        {
            [DebuggerNonUserCode]
            get
            {
                return this._TxtCode;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                KeyEventHandler handler = new KeyEventHandler(this.TxtCode_KeyDown);
                EventHandler handler2 = new EventHandler(this.TxtCode_Leave);
                System.Windows.Forms.KeyPressEventHandler handler3 = new System.Windows.Forms.KeyPressEventHandler(this.TxtCode_KeyPress);
                EventHandler handler4 = new EventHandler(this.TxtCode_GotFocus);
                if (this._TxtCode != null)
                {
                    this._TxtCode.KeyDown -= handler;
                    this._TxtCode.Leave -= handler2;
                    this._TxtCode.KeyPress -= handler3;
                    this._TxtCode.GotFocus -= handler4;
                }
                this._TxtCode = value;
                if (this._TxtCode != null)
                {
                    this._TxtCode.KeyDown += handler;
                    this._TxtCode.Leave += handler2;
                    this._TxtCode.KeyPress += handler3;
                    this._TxtCode.GotFocus += handler4;
                }
            }
        }

        internal virtual TextBox TxtName
        {
            [DebuggerNonUserCode]
            get
            {
                return this._TxtName;
            }
            [MethodImpl(MethodImplOptions.Synchronized), DebuggerNonUserCode]
            set
            {
                EventHandler handler = new EventHandler(this.TxtName_GotFocus);
                if (this._TxtName != null)
                {
                    this._TxtName.GotFocus -= handler;
                }
                this._TxtName = value;
                if (this._TxtName != null)
                {
                    this._TxtName.GotFocus += handler;
                }
            }
        }

        public bool UpperText
        {
            get
            {
                return this.mUpperText;
            }
            set
            {
                this.mUpperText = value;
            }
        }

        public string Value
        {
            get
            {
                return this.mValue;
            }
            set
            {
                if (value.Trim() != this.mValue.Trim())
                {
                    this.mValue = value;
                    if (value == "")
                    {
                        this.TxtCode.Text = "";
                        this.TxtName.Text = "";
                        this.TxtCode.Tag = "";
                    }
                    else
                    {
                        clsDMTaiKhoan khoan = new clsDMTaiKhoan();
                        khoan.Load(value);
                        this.TxtCode.Text = khoan.SoTaiKhoan.Trim();
                        this.TxtCode.Tag = khoan.SoTaiKhoan.Trim();
                        if (modGeneral.H_LANGUAGE == "VIET")
                        {
                            this.TxtName.Text = khoan.TenViet.Trim();
                        }
                        else
                        {
                            this.TxtName.Text = khoan.TenAnh.Trim();
                        }
                    }
                }
            }
        }

        public int WithCode
        {
            get
            {
                return this.mWithCode;
            }
            set
            {
                this.mWithCode = value;
                this.TxtCode.Width = value;
            }
        }

        public delegate void GotfocusEventHandler(object sender, EventArgs e);

        public delegate void KeyPressEventHandler(object sender, KeyPressEventArgs e);

        public delegate void LostFocusEventHandler(object sender, object Subsender, EventArgs e);

        public delegate void ValueChangedEventHandler(object sender, EventArgs e);
    }
}

